
$(document).ready(function(){  
	$("a#pers-bild-upload").click(function(){
		$("#profilbild-area").show();
		$("#pinnwand-area").hide();
		
		url_fileupload = 'uploadimages';
		
		$.getScript("/bundles/acmeperson/js/main.js", function(){
	    	var width = parseInt($(".container").width());
			var marginleft = width / 2;
			
			
			var height = $("body").height() + 50;	
			$("#pers-bild-lightbox").css( { "height":height + "px" } );
			$("#pers-bild-lightbox-panel").width(width);
			$("#pers-bild-lightbox-panel").css({"margin-left" :  "-" + marginleft + "px"});
			
			$("#pers-bild-lightbox, #pers-bild-lightbox-panel").fadeIn(300);  
		});
		
    });  
    
    $("a#close-panel").click(function(){
		var pathArray = window.location.href.split('/');
		protocol = pathArray[0];
		host = pathArray[2];
		url = protocol + '//' + host + $( "input[name='url-check-directory']").val() + '/' + delete_filename;
    	
		$("#aj-set-image-bildupload").show();
		if(delete_filename != ""){
    		$.post( url, { text: $( "textarea[name='pinnwand-upload']").val()  }, function(pinnwand_id){
    			delete_filename = "";
    			url = protocol + '//' + host + $( "input[name='url-index']").val();		
    			$(".pinnwand").load(url + " .pinnwand > *", function(){
    				$(".template-download").load(url + " .template-download > *");
//    				$(".container .row .col-md-2").load(url + " .container .row .col-md-2 > *");
    				$("#aj-set-image-bildupload").hide();
    				$("#pers-bild-lightbox, #pers-bild-lightbox-panel").fadeOut(300);
    			});
    			
    			// send Email
    			url = protocol + '//' + host + $( "input[name='url-send-pinnwand']").val() + '/' + pinnwand_id;
    			$.get( url );
    			
    		});
    		
    		
    	} else {
    		//location.reload();
    		
			url = protocol + '//' + host + $( "input[name='url-index']").val();
			$("#aj-set-image-bildupload-pers").show();
			if($(".pinnwand").length > 0){
				$(".pinnwand").load(url + " .pinnwand > *", function(){
    				$(".template-download").load(url + " .template-download > *");
    				$(".container .row .left-col").load(url + " .container .row .left-col > *");
					// globale variable neu zuordnen
					var imagename = $("#personal-image-profil").attr("src").split('/');
					var n_path = "";
					var n_imagest = "";
					$.each(imagename, function(i, val){
						if(i < 3){
							if(n_path != ""){
								n_path += '/' + val;
							} else {
								n_path = val;	
							}
							
						} 
						n_imagest = val;
					});
					imagest = n_imagest;
					path = n_path + '/files/';
					$("#aj-set-image-bildupload-pers").hide();
					$("#pers-bild-lightbox, #pers-bild-lightbox-panel").fadeOut(300);
				});
			} else {
				// wenn nicht in index bereich
				$("#aj-set-image-bildupload-pers").hide();
				$("#pers-bild-lightbox, #pers-bild-lightbox-panel").fadeOut(300);
			}		
    	}
    	
    	
    	
    	
    	
    	
		//
    	
    }); 
    

    
    
});  